﻿using MediatR;
using S.EarTag.API.Mediator.MediatorCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IEarTagRepository;

namespace S.EarTag.API.Mediator.MediatorCommandHandler
{
    public class EarTagCreateCommandHandler : IRequestHandler<EarTagCreateCommand, bool>
    {
        private readonly IEarTagModelRepository _earTagModelRepository;
        public EarTagCreateCommandHandler(IEarTagModelRepository earTagModelRepository)
        {
            _earTagModelRepository=earTagModelRepository;
        }
        /// <summary>
        /// 添加耳标管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(EarTagCreateCommand request, CancellationToken cancellationToken)
        {
            return await _earTagModelRepository.AddAsync(new EarTagModel
            {
                WarehousingDate = request.WarehousingDate,
                BirthState = request.BirthState,
                BreedItem = request.BreedItem,
                EarTag = request.EarTag,
                UseState = "未使用",
                CreateBy = request.CreateBy,
                CreateDate = request.CreateDate = DateTime.Now,
                UpdateBy = request.UpdateBy = "",
                UpdateDate = request.UpdateDate = "",
            });
        }
        
    }
}
